package com.myx.servlet.admin.news;

import com.myx.service.news.NewsService;
import com.myx.service.news.NewsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "DeleteNewsServlet")
public class DeleteNewsServlet extends HttpServlet {
    NewsService newsService=new NewsServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String newsIdStr = request.getParameter("newsId");
        Integer newsId=null;
        if (newsIdStr != null) {
            newsId = Integer.parseInt(newsIdStr);
        }
        boolean isDelete= newsService.deleteNews(newsId);
        if (isDelete){
            request.getRequestDispatcher("/jsp/admin/news/index.jsp").forward(request,response);
        }else {
            System.out.println("删除新闻失败");
        }

    }
}
